package com.base.system.base.db.specifications;

import javax.persistence.criteria.*;

public class IsNotEmptySpecification<T> extends AbstractSpecification<T> {

    private static final long serialVersionUID = 9055195053466525366L;
    private final String property;

    public IsNotEmptySpecification(String property, JoinType joinType) {
        this.property = property;
        this.joinType = joinType;
    }

    @Override
    public Predicate toPredicate(Root<T> root, CriteriaQuery<?> cq, CriteriaBuilder cb) {
        From from = getFrom(property, root);
        String attr = getProperty(property);
        return cb.isNotEmpty(from.get(attr));
    }
}
